//
//  TSWalletRecordTableViewCell.swift
//  TSProfitProject
//
//  Created by TMS on 2019/11/8.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit
import HandyJSON

struct TSWalletRecordModel : HandyJSON {
    
    var title : String?
    var value : String?
}

class TSWalletRecordTableViewCell: UITableViewCell {
    
    var titleLabel : UILabel!
    var dateLabel : UILabel!
    var amountLabel : UILabel!
    var line : UIView!
    var recordModel : TSWalletRecordModel?

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        configViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    public func setupCell(model : TSWalletRecordModel, last:Bool) {
        recordModel = model
//        titleLabel.text = model.title
//        valueLabel.text = model.value
        line.isHidden = last
    }
    
    func configViews() {
        
        amountLabel = UILabel.init()
        amountLabel.textAlignment = .right
        amountLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#FFB182")
        amountLabel.font = UIFont.systemFont(ofSize: 16, weight: .regular)
        amountLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
        contentView.addSubview(amountLabel)
        amountLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview().inset(15)
            make.centerY.equalToSuperview()
        }
        
        titleLabel = UILabel.init()
        titleLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#323232")
        titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .regular)
        contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.top.equalTo(15)
            make.right.equalTo(amountLabel.snp.left).offset(-10)
        }
        
        dateLabel = UILabel.init()
        dateLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#969696")
        dateLabel.font = UIFont.systemFont(ofSize: 12, weight: .regular)
        contentView.addSubview(dateLabel)
        dateLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp.bottom).offset(8)
            make.right.equalTo(amountLabel.snp.left).offset(-10)
        }
    
        line = UIView.init()
        line.backgroundColor = UIColor.hexadecimalColor(hexadecimal: "#F3F8FB")
        contentView.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }
}
